package com.yanqu.road.server.manager.activity.apprentice.handler.impl;

import com.yanqu.road.entity.activity.apprentice.ApprenticeEffectBuffProject;
import com.yanqu.road.entity.activity.apprentice.config.ApprenticeConfig;
import com.yanqu.road.entity.activity.apprentice.config.ApprenticeProjectConfig;
import com.yanqu.road.entity.activity.apprentice.data.ApprenticeBuffProjectData;
import com.yanqu.road.entity.activity.apprentice.enums.ApprenticeProjectSortEnum;
import com.yanqu.road.entity.enums.eOccupationType;
import com.yanqu.road.server.manager.activity.apprentice.CrossApprenticeActivity;
import com.yanqu.road.server.manager.activity.apprentice.handler.ApprenticeProjectHandler;
import com.yanqu.road.server.manager.activity.apprentice.handler.param.ApprenticeCountSortAddRateReq;
import com.yanqu.road.server.manager.activity.apprentice.handler.param.ApprenticeCountTalentAddRateReq;
import com.yanqu.road.server.manager.activity.apprentice.handler.param.ApprenticeDoProjectReq;
import com.yanqu.road.server.manager.activity.apprentice.handler.param.ApprenticeDoProjectResp;

import java.util.*;

public class ApprenticeDoProjectType13Handler implements ApprenticeProjectHandler {

    /**
     * 执行项目
     * @param req
     * @return
     */
    @Override
    public ApprenticeDoProjectResp doProject(ApprenticeDoProjectReq req) {
        return null;
    }

    /**
     * |接下来{0}次行程，|每多选择一个不同职业项目，当次天资{2}。
     * @param req
     */
    @Override
    public void countTalentTypeAddRate(ApprenticeCountTalentAddRateReq req) {
        CrossApprenticeActivity activity = req.getActivity();
        ApprenticeConfig config = activity.getConfig();
        ApprenticeProjectConfig projectConfig = req.getProjectConfig();
        Map<Integer, Integer> resultMap = req.getResultMap();
        ApprenticeBuffProjectData buffProjectData = req.getBuffProjectData();
        //buff次数减一
        buffProjectData.addNum(-1);
        //单个相同加成rate
        int oneSameAddRate = Integer.parseInt(projectConfig.getParam()) - 1000;
        //选择的职业类型SET
        Set<Integer> talentTypeSet = new HashSet<>();
        for (int selectProjectId : req.getSelectProjectIds()) {
            ApprenticeProjectConfig selectProjectConfig = config.getProjectConfig(selectProjectId);
            if (selectProjectConfig == null) {
                continue;
            }
            if (selectProjectConfig.getSort() == ApprenticeProjectSortEnum.SORT_TYPE_0.getType()) {
                continue;
            }
            int talentType = Integer.parseInt(selectProjectConfig.getParam());
            talentTypeSet.add(talentType);
        }
        //不同职业数
        int diffNum = talentTypeSet.size();
        int addRate = 0;
        if (diffNum > 1) {
            //注入加成值到MAP
            addRate = (diffNum - 1) * oneSameAddRate;
            for (eOccupationType type : eOccupationType.values()) {
                int talentType = type.getValue();
                int oldRate = resultMap.getOrDefault(talentType, 0);
                resultMap.put(talentType, oldRate + addRate);
            }
        }
        //生效buff结果结果集注入
        List<ApprenticeEffectBuffProject> effectBuffProjects = req.getEffectBuffProjects();
        ApprenticeEffectBuffProject effectBuffProject = new ApprenticeEffectBuffProject(buffProjectData.getProjectId(), addRate);
        effectBuffProjects.add(effectBuffProject);
    }

    @Override
    public void countSortTypeAddRate(ApprenticeCountSortAddRateReq req) {

    }
}
